package cn.edu.hit.core.functional;

import java.util.Objects;
import java.util.function.BiFunction;
import java.util.function.Function;

/**
 * Created by Wang on 2017/5/27.
 */
@FunctionalInterface
public interface TriFunction<T, K, U, R> {
    R apply(T t, K k, U u);

    default <V> TriFunction<T, K, U, V> andThen(Function<? super R, ? extends V> after) {
        Objects.requireNonNull(after);
        return (T t, K k, U u) -> after.apply(apply(t, k, u));
    }

    default BiFunction<K, U, R> adaptFirst(T t) {
        return (k, u) -> this.apply(t, k, u);
    }

    default BiFunction<T, U, R> adaptSecond(K k) {
        return (t, u) -> this.apply(t, k, u);
    }

    default BiFunction<T, K, R> adaptThird(U u) {
        return (t, k) -> this.apply(t, k, u);
    }
}
